#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

// 通过输出参数打开节点
int main(int argc, char *argv[])
{
    int fd;
    unsigned char val;
    if (argc != 2)
    {
        printf("Usage: <./app> </dev/xxx>\r\n");
        return -1;
    }

    fd = open(argv[1], O_RDWR);
    if (fd < 0)
    {
        printf("open %s is err\r\n", argv[1]);
        return -1;
    }

    // 循环写入0和1
    while (1)
    {
        val = '0';
        write(fd, &val, 1);
        sleep(1);
        val = '1';
        write(fd, &val, 1);
        sleep(1);
    }

    close(fd);

    return 0;
}
